#include <iostream>
#include <map>
#include "lib/coreploader.hpp"
#include "lib/coreqmanager.hpp"
#include "lib/coresettings.hpp"
#include <boost/thread.hpp>
#include "lib/corechain.hpp"
using namespace std;
using namespace pland;

void writer(SharedDQueue qin)
{
	while(true)
	{
        char* buff = new char[2048];
		Data_Header *h = new Data_Header;
        h->size = 2048;
        SharedData d(new Data(buff, h));
		qin->push(d);
	}
}

void reader(SharedDQueue qout)
{
    int count = 0;
	while(true)
	{
        SharedData d = qout->pop();
        count++;
        if(count%10000 == 0)
            cout << "." << flush;
	}
}

int main()
{
    //QueueManager *man = QueueManager::Instance();
    Chain *c = new Chain();
    utill_log(std::string(__FILE__) + " Loaded XML");

    try
    {
        c->create_chain("chain.xml");
        utill_log(std::string(__FILE__) + " Loaded XML");

    }
    catch(Exeption a)
    {
        return 0;
    }
    vector<Chain::Chain_Queue> sources = c->sourceQueues();
    vector<Chain::Chain_Queue> sinks = c->sinkQueues();
    boost::thread_group g;
    for(int i = 0; i< sources.size(); i++)
    {
        g.add_thread(new boost::thread(writer, sources[i].queue));
    }
    for(int i = 0; i< sinks.size(); i++)
    {
        g.add_thread(new boost::thread(reader, sinks[i].queue));
    }
    utill_log(std::string(__FILE__) + " Loaded XML");

    c->start();
    //man->start();
    char a;
    cin >> a;
    //man->removeAll();
}
